 package nz.ac.massey.doi_information_extractor.tests;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertTrue;
import nz.ac.massey.doi_information_extractor.data.Author;
import nz.ac.massey.doi_information_extractor.data.AuthorList;
import nz.ac.massey.doi_information_extractor.data.Publication;
import nz.ac.massey.doi_information_extractor.output.OutputException;
import nz.ac.massey.doi_information_extractor.output.PDFOutput;

public class OutputTest{
	Publication publication;
	PDFOutput output;

	@Before
	public void setUp(){
		AuthorList al = new AuthorList();
		al.add(new Author(1,"First1","last1","organization1","department1","authortype1","userId1"));
		al.add(new Author(2, "First2", "last2", "organization2", "department2","authortype2","userId2"));

		publication = new Publication("description", "Journal",
				"pageNumbers", "publicationTitle", true, true,
				true, "1", "articleTitle", "date", "url", "issn",
				al, "publisher", "keywords", "conferenceLocation",
				"conferenceDates", "publisherLocation", "editors", "journalEdition",
				"1", "doi", 1, "1234567890");
		output = new PDFOutput();
	}

	@After
	public void tearDown(){
		publication = null;
		output = null;
	}

	/**
	 * Initial test case, makes simple pdf output file and tests for
	 */
	@Test
	public void test1(){
		try {
			output.outputToPdf(publication, "build/outputTest1.pdf");
			assertTrue(true);
		} catch (OutputException e) {
			e.printStackTrace();
			assertTrue(false);
		}
	}

	@Test
	public void test2(){
		try {
			output.outputToPdf(publication, "build");
			assertTrue(false);
		} catch (OutputException e) {
			System.out.println(e.getMessage());
			assertTrue(e.getMessage().equals("Error creating PDF file"));
		}
	}


	@Test
	public void testJournal(){
		publication.setPublicationType("Journal");
		publication.setResearchOrProfCom(false);
		publication.setQualityAssured(false);
		publication.setConfidential(false);

		try{
			output.outputToPdf(publication, "build/outputTest3.pdf");
			assertTrue(true);
		}catch(OutputException ex){
			assertTrue(false);
		}
	}

	@Test
	public void testConference(){
		publication.setPublicationType("Conference");
		publication.setResearchOrProfCom(true);
		publication.setQualityAssured(true);
		publication.setConfidential(true);


		try{
			output.outputToPdf(publication, "build/outputTest4.pdf");
			assertTrue(true);
		}catch(OutputException ex){
			assertTrue(false);
		}
	}

	@Test
	public void testBook(){
		publication.setPublicationType("Book");
		publication.setResearchOrProfCom(true);
		publication.setQualityAssured(false);
		publication.setConfidential(true);


		try{
			output.outputToPdf(publication, "build/outputTest5.pdf");
			assertTrue(true);
		}catch(OutputException ex){
			assertTrue(false);
		}
	}
}
